package miracle.joker.design.command.demo2;

public class Document {
    private StringBuilder content = new StringBuilder();
    private int cursor = 0;

    public void appendText(String text) {
        content.insert(cursor, text);
        cursor += text.length();
    }

    public void deleteText() {
        if (cursor > 0) {
            content.deleteCharAt(cursor - 1);
            cursor--;
        }
    }

    public void moveCursor(int steps) {
        cursor += steps;
        cursor = Math.max(0, Math.min(content.length(), cursor));
    }

    public String getContent() {
        return content.toString();
    }

    public int getCursor() {
        return cursor;
    }
}
